### Lab6-1 ### 建立一個 Streamlit 的 Python 3.11 的虛擬環境 ~$ python -m venv --system-site-packages ~/streamlit_311 ~$ source ~/streamlit_311/bin/activate ### Lab6-2 ### # 安裝 streamlit 的模組 (streamlit_311) ~$ pip install streamlit # 下載講師提供的範例程式 (streamlit_311) ~$ wget http://max543.com/debugger/class/python02/%E5%BD%B1%E5%83%8F%E8%BE%A8%E8%AD%98%20X%20%E6%A8%B9%E8%8E%93%E6%B4%BE%205_2025/example/ch03.zip # 解壓縮 (streamlit_311) ~$ unzip ch03.zip # 進入資料夾 ch03 (streamlit_311) ~$ cd ch03 # 執行 runApp1.py、run3-1.py ~ run3-19.py、runApp2.py,皆可正常執行。例如:執行 run3-19.py。 (streamlit_311) ~/ch03$ python run3-19.py ### Lab6-3 ### # 安裝 ultralytics (streamlit_311) ~$ pip install ultralytics # opencv-python (streamlit_311) ~$ pip install opencv-python # 下載講師提供的範例程式 ch06.zip (streamlit_311) ~$ wget http://max543.com/debugger/class/python02/%E5%BD%B1%E5%83%8F%E8%BE%A8%E8%AD%98%20X%20%E6%A8%B9%E8%8E%93%E6%B4%BE%205_2025/example/ch06.zip # 解壓縮 (streamlit_311) ~$ unzip ch06.zip # 進入資料夾 ch03 (streamlit_311) ~$ cd ch06 # 進入資料夾 YOLO_Streamlit_App_pi5 (streamlit_311) ~$ cd ch06 # 執行 runApp.py 程式碼 (streamlitenv_311) ~/ch06$ python runApp.py ### Lab6-4 ### # 建立一個 groq 的 Python 3.11 的虛擬環境 ~$ python -m venv --system-site-packages ~/groq_311 ~$ source ~/groq_311/bin/activate # 安裝 Groq API 的 Python 套件 (groq_311) ~$ pip install groq ### Lab6-5 ### # 下載講師提供的範例程式 ch04.zip (Chapter 4:本機 LLM Vision 整合應用) (groq_311) ~$ wget http://max543.com/debugger/class/python02/%E5%BD%B1%E5%83%8F%E8%BE%A8%E8%AD%98%20X%20%E6%A8%B9%E8%8E%93%E6%B4%BE%205_2025/example/ch04.zip # 解壓縮 (groq_311) ~$ unzip ch04.zip # 進入 ch04 (groq_311) ~$ cd ch04 ### Lab6-6 ### # 安装 PIL(Python Imaging Library)模組,用來處理圖檔 (groq_311) ~$ pip install Pillow ### Lab6-7 ### # 安裝 streamlit 的模組 (streamlit_311) ~$ pip install streamlit ### Lab6-8 ### # 更新和升級套件 (groq_311) ~$ sudo apt-get update (groq_311) ~$ sudo apt-get upgrade # 需要確認是否安裝 crul 套件 (通常 Raspberry Pi OS 預設有安裝) (groq_311) ~$ sudo apt-get install -y curl # 使用 sudo crul 安裝 Ollama (groq_311) ~$ sudo curl -fsSL https://ollama.com/install.sh | sh # 顯示安裝的 Ollama 版本 (groq_311) ~$ ollama --version ### Lab6-9 ### # 在 Ollama 是使用 run 指令來執行 TinyLlama 模型 (groq_311) ~$ ollama run tinyllama # 測試提示語 """Can you analyze the following sentence to determine if it is ON or OFF? ... Please Turn off the lights in the room. And just say ON or OFF.""" # 顯示目前安裝的模型 (groq_311) ~$ ollama list # 刪除安裝的模型 (groq_311) ~$ ollama rm <模型名稱> # 停止 Ollama 服務 (groq_311) ~$ sudo systemctl stop ollama # 啟動 Ollama: (groq_311) ~$ sudo systemctl start ollama # 將某個模型卸載 (不關 ollama 服務) (groq_311) ~$ ollama stop <模型名稱> # 重啟 Ollama 服務 (停止所有模型但不會刪除模型檔,會釋放記憶體) (groq_311) ~$ sudo systemctl restart ollama ### Lab6-10 ### # 編輯設定檔 ~$ sudo nano /etc/dphys-swapfile # 套用 Swap 設定 ~$ sudo systemctl restart dphys-swapfile # 查看 Swap 大小 ~$ free -h # 查看 Swap 類型 ~$ swapon --show ### Lab6-11 ### # zram 設定指令 ~$ sudo dphys-swapfile swapoff # 關閉 dphys-swapfile ~$ sudo systemctl disable dphys-swapfile # 停止 dphys-swapfile ~$ sudo apt install zram-tools # 安裝 zram ~$ sudo systemctl enable --now zramswap # 啟用 zramswap ~$ sudo reboot # 重開機 # 編輯設定檔 ~$ sudo nano /etc/default/zramswap # 重新啟動 zram ~$ sudo systemctl restart zramswap # 查看 Swap 類型 ~$ swapon --show ### Lab6-12 ### # 在 Ollama 是使用 run 指令來執行 Gemma 2:2B 模型 (groq_311) ~$ OLLAMA_NUM_GPU=1 ollama run gemma2:2b ### Lab6-13 ### # 在 Ollama 是使用 run 指令來執行 Phi3 模型 (groq_311) ~$ OLLAMA_NUM_GPU=1 ollama run phi3 ### Lab6-14 ### # 在 Ollama 是使用 run 指令來執行 Llama3 模型 (groq_311) ~$ OLLAMA_NUM_GPU=1 ollama run llama3 ### Lab6-15 ### # 進入 grop_311 的虛擬環境 ~$ source ~/groq_311/bin/activate # 在虛擬環境安裝 ollama 套件 (groq_311) ~$ pip install ollama ### Lab6-16 ### # 確認啟動 Ollama 服務 (groq_311) ~$ ollama serve # 檢查安裝了哪些模型 (groq_311) ~$ ollama list ### Lab6-17 ### # 安裝 qwen3-vl:4b 模型 (groq_313) ~$ OLLAMA_NUM_GPU=1 ollama run qwen3-vl:4b ### Lab6-18 ### # ngork 官網 https://ngrok.com/ # 在樹莓派上安裝 ngrok (groq_313) ~$ curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \ | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \ && echo "deb https://ngrok-agent.s3.amazonaws.com bookworm main" \ | sudo tee /etc/apt/sources.list.d/ngrok.list \ && sudo apt update \ && sudo apt install ngrok # 設定 ngrok 的 authtoken (groq_313) ~$ ngrok config add-authtoken 你的 authtoken # 啟用你的網路埠號,例如:http 的 port 8501 (groq_313) ~$ ngrok http 8501 ### Lab6-19 ### # 啟用 tcp port 22 (groq_313) ~$ ngrok tcp 22